<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="相册名称" prop="name">
        <el-input v-model="formData.name" placeholder="请输入相册名称" clearable :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="相册描述" prop="description">
        <el-input v-model="formData.description" placeholder="请输入相册描述" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="排序序号" prop="sort">
        <el-input v-model="formData.sort" placeholder="请输入排序序号" clearable :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import albumApi from "../../../request/api/album";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        name: undefined,
        description: undefined,
        sort: undefined,
      },
      rules: {
        name: [{
          required: true,
          message: '请输入相册名称',
          trigger: 'blur'
        }],
        description: [{
          required: true,
          message: '请输入相册描述',
          trigger: 'blur'
        }],
        sort: [{
          required: true,
          message: '请输入排序序号',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    let albumId = this.$route.params.albumId;
    this.albumApi.queryById({id:albumId}).then((res) => {
      console.log("新增相册", res);
      if (res.data.state == 200) {
        this.formData=res.data.data
        // this.$router.push('/home/product/albummanage')
      } else {
        this.$alert(res.data.message, "提示");
      }
    });
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        this.albumApi
            .update(this.formData)
            .then((res) => {
              console.log("新增相册", res);
              if (res.data.state == 200) {
                this.$router.push('/home/product/albummanage')
              } else {
                this.$alert(res.data.message, "提示");
              }
            });
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
  }
}

</script>
<style>
</style>
